<?php


namespace backend\controllers;


use common\models\Equity;
use common\models\EquityClassify;
use common\services\MenuService;
use Yii;

class EquityController extends BaseController
{
    public function init()
    {
        parent::init();
        $this->model = Equity::className();
    }

    public function actionIndex()
    {
        $this->model = EquityClassify::className();
        return parent::actionIndex();
    }
    public function actionAdd()
    {
        $this->model = EquityClassify::className();
        return parent::actionAdd();
    }
    public function actionEdit()
    {
        $this->model = EquityClassify::className();
        return parent::actionEdit();
    }

    public function actionClassDrop()
    {
        $this->model = EquityClassify::className();
        return parent::actionDrop();
    }
    public function actionList()
    {
        if (Yii::$app->request->isPost){
            $data = parent::actionIndex();
            $c_ids = array_column($data['data'],'c_id');
            $classify = EquityClassify::find()->where(['id'=>$c_ids])->select(['id','name'])->asArray()->all();
            $classify = array_column($classify,'name','id');
            foreach ($data['data'] as &$datum){
                $datum['c_id'] = $classify[$datum['c_id']]??'';
            }
            return $data;
        }
        return parent::actionIndex();
    }

    public function actionListAdd()
    {
        $classify = EquityClassify::find()->where(['status'=>1])->select(['id','name'])->asArray()->all();
        $classify = array_column($classify,'name','id');
        Yii::$app->view->params['classify']= $classify;
        Yii::$app->view->params['leftHtml']= MenuService::getSubmenu();
        return parent::actionAdd();
    }

    public function actionListEdit()
    {
        $classify = EquityClassify::find()->where(['status'=>1])->select(['id','name'])->asArray()->all();
        $classify = array_column($classify,'name','id');
        Yii::$app->view->params['classify']= $classify;
        Yii::$app->view->params['leftHtml']= MenuService::getSubmenu();
        return parent::actionEdit();
    }
}